package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;

/**
 * 字符串常量池
 *
 * @author hqd
 */
@Getter
public class ConstantUtf8Info extends ConstantPool {
    private String bytes;
    private Integer length;

    public ConstantUtf8Info(ConstantInfoType tag, ClassFile classFile) {
        super(tag, classFile);
        this.length = HexStrTransformUtil.parseHexToInt(classFile.readU2());
        this.bytes = HexStrTransformUtil.pareHexToStr(classFile.read(length));
    }

    @Override
    public String getVal() {
        return bytes.trim().intern();
    }
}
